/**
 * @param {number[]} nums
 * @param {number} k
 * @return {void} Do not return anything, modify nums in-place instead.
 */
var rotate = function (nums, k) {
  k = k % nums.length;
  if (k === 0) {
    return nums;
  }
  reverse(nums, 0, nums.length - 1);
  reverse(nums, 0, k - 1);
  reverse(nums, k, nums.length - 1);
  return nums;
};

function reverse(nums, s, e) {
  while (e > s) {
    let t = nums[s];
    nums[s] = nums[e];
    nums[e] = t;
    s++;
    e--;
  }
}
